package com.carkeeper.user.controller;

import com.alibaba.excel.EasyExcel;
import com.carkeeper.common.utils.Result;
import com.carkeeper.common.utils.StatusCode;
import com.carkeeper.user.pojo.Car;
import com.carkeeper.user.pojo.User;
import com.carkeeper.user.service.CarService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.net.URLEncoder;
import java.util.List;

@RestController
@RequestMapping("/car")
@Api(tags = "车主车辆接口api")//标签专门用来标注类的
public class CarController {
    @Autowired
    private CarService carService;

    /*
     * 根据userId查car集合
     * */
    @GetMapping("/findById/{userId}")
    @ApiOperation("车主id查车主车辆接口")//标注方法
    @ApiImplicitParams({//参数集合
            @ApiImplicitParam(name = "id",value = "主键")
    })
    public Result findById(@PathVariable("userId") Integer userId){
        try {
            List<Car> list = carService.findByUserId(userId);
            return new Result(true, StatusCode.OK,"查询成功",list);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"查询失败");
        }
    }

    /*
     * 根据tb_order表的car_code查car信息
     * */
    @GetMapping("/findByOrderCode/{code}")
    @ApiOperation("车牌号查询车辆接口")//标注方法
    @ApiImplicitParams({//参数集合
            @ApiImplicitParam(name = "code",value = "车牌号")
    })
    public Result<Car> findByOrderCode(@PathVariable("code") String code){
        try {
            Car car = carService.findByOrderCode(code);
            return new Result<Car>(true, StatusCode.OK,"查询成功",car);
        }catch (Exception e){
            e.printStackTrace();
            return new Result<Car>(false, StatusCode.ERROR,"查询失败");
        }
    }
}
